package com.ebt.m.users;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.commons.buscomponent.listview.IView;
import com.ebt.m.commons.utils.Logger;
import com.ebt.m.users.bean.CardTagData;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CardTagView extends IView {


    @BindView(R.id.carddata_tag_name)
    TextView carddataTagName;
    @BindView(R.id.item_root)
    LinearLayout itemRoot;
    @BindView(R.id.tag_divider)
    View tagDivider;
    @BindView(R.id.iv_empty)
    ImageView ivEmpty;

    public CardTagView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inflate(context, R.layout.layout_carddata_tag, this);
        ButterKnife.bind(this);
    }

    public CardTagView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CardTagView(Context context) {
        this(context, null);
    }

    @Override
    public void update(Object... obj) {
        try {
            CardTagData tagData = (CardTagData) obj[0];
            carddataTagName.setText(tagData.title);
            tagDivider.setVisibility(tagData.showDivider ? View.VISIBLE : View.GONE);
            if (tagData.showEmpty) {
                ivEmpty.setVisibility(View.VISIBLE);
                ivEmpty.setBackgroundResource(tagData.type == 1 ? R.drawable.cardhonour_list_empty : R.drawable.cardservice_list_empty);
            } else {
                ivEmpty.setVisibility(View.GONE);
            }
        } catch (Exception e) {
            Logger.e(e);
        }

    }


}
